using System;
using Headsight.BPMN2WF.BPMN.Model;
using Headsight.BPMN2WF.BPMN.Schemas;
using Headsight.BPMN2WF.Transformation;
using Headsight.BPMN2WF.Transformation.BPMN2TransformerMappings.Additions;
using Headsight.BPMN2WF.WF.Simplification;

namespace Headsight.BPMN2WF
{
    /// <summary>
    /// Factory creating <see cref="IBPMN2WF"/> instances.
    /// </summary>
    public static class BPMN2WFFactory
    {
        /// <summary>
        /// Constructs and returns a new <see cref="IBPMN2WF"/> instance using the 
        /// passed in <para>registry</para> for the transformation of BPMN artifacts
        /// to WF artifacts.
        /// </summary>
        public static IBPMN2WF Create(IBPMN2WFTransformations registry, Boolean simplifyWFModel = true, /*
          * not really best place here (temporary solution) but I wanna have
          * the 'visualization / alignment' stuff outside of 'BPMNFlowNodesBlock' (as it has been in the past)
          * and therefore 'visualization being orthogonal to 'BPMNFlowNodesBlock'.  
          */
            tDefinitions tDefinitions = null)
        {
            IBPMN2WFTransformations reg = new BPMN2WFTransformationsCacheWrapper(registry);
            reg = new BPMN2WFTransformationsResultsCollectorWrapper(reg);

            if (tDefinitions != null)
            {
                // second parameter is also (only) temporary...
                reg = new BPMN2WFTransformationsLayouterWrapper(reg, new BPMNElementVisualFactory().Create(tDefinitions));
            }

            if (simplifyWFModel)
            {
                reg = new BPMN2WFTransformationsSimplifierWrapper(reg);
            }

            reg = new BPMN2WFTransformationsExceptionHandlerWrapper(reg);

            return new BPMN2WFImpl(reg);
        }
    }
}